home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / C++ A'Link Files / Feb 91 / CPlus.Dev$ 2⁄22⁄91 / 0277-Ellipses-Feb91 < prev    next >
Encoding:
Text File  |  1991-03-06  |  3.2 KB  |  81 lines  |  [TEXT/GEOL]

  1. Item    3215647                         19-Feb-91        13:04PST
  2.  
  3. From:   U0922                           NYU Medical Ctr, Martin Nachbar,HEP
  4.  
  5. To:     CPLUS.DEV$                      C++ Interest List--Developers
  6.  
  7. Item forwarded by       ALCABES      to CPLUS.APPLE$ 
  8.  
  9. ------------------------------------------------------------------------------
  10.  
  11. Sub:    Ellipses
  12.  
  13. Attn: CPLUS DEV$
  14. SentBy: Adam Hunger
  15. Date   2/19/91
  16. Subject    Ellipses
  17. From   Adam Hunger
  18. To CPLUS DEV$
  19.  
  20.                        Subject:                               Time:12:05 PM
  21.   OFFICE MEMO          Ellipses                               Date:2/19/91
  22. Ok,  I admit it...
  23.  
  24. I've been writing my own vector and matrix classes for c++ so that I can hone
  25. my c++ skills and do cross development between our SGI and Mac.
  26.  
  27. I wanted to write a constructor for my vector class that could take a variable
  28. number of floats.  After several abortive attemps at using a vector::vector
  29. constructor, I finally traced the problem down to what appears to be a stack
  30. handling error, compiler bug, or user stupidity.
  31.  
  32. I looked for a source that might work (source code devoid of my human
  33. frailties).  On page 123 of "The C++ Answer Book" by Tony L. Hansen I found an
  34. error routine (included in full for you compilation pleasure) which I modified
  35. (after testing) to include floats.  The footnote on the bottom of the page
  36. says:
  37.  
  38. "ANSI C has changed the rules slightly from those in effect when The C++
  39. Programming Language was written.  Formerly, all variables of type char, short
  40. and float were automatically promoted to ints and doubles when passed to
  41. functions.  C++ and C compilers are now required to do this only when a
  42. variabale argument list is being used or when, in the case of C, the older
  43. function declaration style is used.  Otherwise, the compiler is free to pass a
  44. char on the stack as a char, and likewise a short and a float."  Whew.
  45.  
  46. The declaration:
  47.     void error(const char *fmt ...)
  48. and the use of <stdarg.h> works splendidly for char and int data; however,
  49. pass a float, and you'll see all sorts of garbage (the SGI will crash).  This
  50. made me wonder if my float was being promoted to a double.  I wrote a little
  51. stack sniffer that used a char * pointer to walk byte by byte (forwards and
  52. backwards) through the stack and recaste the pointer to floats and doubles.
  53. I've tried compiliing with all floats as doubles to eliminate the possibility
  54. of float promotion to doubles; this also failed.
  55.  
  56. The problem is that these stack errors only occur for undeclared arguments.
  57. For MPW C++ 3.1  if you have a function (not even a member function or a
  58. constructor) such as:
  59.  
  60. int passit(int n, float f1 ...)
  61.    where n is the number of floats being passed
  62.              f1 is the first float
  63.  
  64. Then you can create a pointer to f1, but all arguments after f1 are garbled.
  65. For:
  66.  
  67. int passit(int n, float f1, float f2 ...)
  68.  
  69. you can create a float * fptr to f1, and use it to walk to f2, but all
  70. arguments on the stack after f2 are then garbled (or nonexistant?...I doubt
  71. it).
  72.  
  73. What is going on?  Are bytes being reversed on the stack for doubles?  What's
  74. happening with the stackframe?  Why should something apparently so easy waste
  75. so much of my time?
  76.  
  77. Many thanks for any input at all,
  78.  
  79. Adam Hunger,  212-263-5744
  80.  
  81.